﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace IslandInterloper.Engine
{
    public static class Utilities
    {
        internal static string[] ChildXElementsToStringArray(XElement theElement, out bool success)
        {
            List<string> result = new List<string>();
            success = true;
            foreach (XElement element in theElement.Elements())
            {
                result.Add(element.Name.LocalName);
            }
            return result.ToArray();
        }

        internal static double XElementToDouble(XElement element)
        {
            double result = 0;
            double.TryParse(element.Value, out result);
            return result;
        }
        internal static int XElementToInt(XElement element)
        {
            int result = 0;
            int.TryParse(element.Value, out result);
            return result;
        }
        internal static bool XElementToBool(XElement element)
        {
            bool result = false;
            bool.TryParse(element.Value, out result);
            return result;
        }
        internal static int FromStringToInt(string source)
        {
            int result = 0;
            int.TryParse(source,out result);
            return result;
        }
        internal static string FromStringToString(string source)
        {
            return source;
        }
        internal static double NormalizeDegrees(double degrees)
        {
            return degrees - Math.Floor(degrees / 360) * 360;
        }
    }
}
